package com.company.project.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.company.project.service.HelloWorldService;

@RestController
@EnableConfigurationProperties
@RequestMapping("helloWorld")
public class HelloWorldController {
	
	@Value("${spring.application.name}")
	private String name ;
	
	@Autowired
	private HelloWorldService helloWorldService ;
	
	@GetMapping
	public String HelloWorld(HttpServletRequest request) {
		
		HttpSession session = request.getSession();
		session.setAttribute("website","www.wanghongquan.youdontcare.com");
		
		return helloWorldService.sayHelloWorld() + " " + name;
	}
	
	@RequestMapping("getSession")
	public String getSession(HttpServletRequest request) {
		HttpSession session = request.getSession();
		String sessionId = (String)session.getId();
		String website = (String)session.getAttribute("website");
		
		return "sessionId:" + sessionId + ", session: "+ website;
	}

	public HelloWorldService getHelloWorldService() {
		return helloWorldService;
	}

	public void setHelloWorldService(HelloWorldService helloWorldService) {
		this.helloWorldService = helloWorldService;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
}
